package com.njtoyo.taxi.admin.rest.controller.business.operation_rule;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.njtoyo.taxi.admin.aop.PermissionScope;
import com.njtoyo.taxi.admin.rest.presenter.business.operation_rule.DriverServiceArrangementPresenter;
import com.njtoyo.taxi.admin.rest.wrapper.business.operation_rule.DriverServiceArrangementWrapper;
import com.njtoyo.taxi.admin.rest.wrapper.business.operation_rule.QrCodeCreateWrapper;
import com.njtoyo.taxi.admin.service.business.operation_rule.QrCodeService;
import com.taxi.entity.common.RestResult;
import com.njtoyo.taxi.entity.backend.AdminUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RestController
@Api(value = "二维码配置", tags = "二维码配置")
@RequestMapping("business/operation-rule/qr-code")
public class QrCodeController {
    @Autowired
    private QrCodeService qrCodeService;

    @GetMapping("")
    @ApiOperation(value = " 二维码列表", notes = "二维码列表，权限：driver_register_qr_code")
    @PermissionScope(names = {"driver_register_qr_code"})
    RestResult<IPage<DriverServiceArrangementPresenter>> index(@ModelAttribute("admin") AdminUser adminUser,
                                                               DriverServiceArrangementWrapper wrapper) {
        return qrCodeService.page(adminUser, wrapper);
    }

    @PostMapping("")
    @ApiOperation(value = "添加二维码", notes = "添加二维码，权限：driver_register_qr_code_edit")
    @PermissionScope(names = {"driver_register_qr_code_edit"})
    RestResult create(@ModelAttribute("admin") AdminUser adminUser,
                      @RequestBody @Valid QrCodeCreateWrapper wrapper) {
        return qrCodeService.create(adminUser, wrapper);
    }
}
